/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gradius;

import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;

/**
 *
 * @author Firedemon
 */
public class PlayerShip 
{
    private int    x, y;
    private Image  image;
    private GradiusGame game;
    private double dx;
    private double dy;
        
    PlayerShip(GradiusGame game, int x, int y)
    {
        this.x = x;
        this.y = y;
        this.game  = game;
        this.image = new ImageIcon(this.getClass().getResource("../sprites/ship.png")).getImage();
    }
    
    public void move(long delta)
    {
        //left stop
        if ((dx < 0) && (x < 10)) 
            return;

        //right stop
        if ((dx > 0) && (x > 1270 - image.getWidth(null))) 
            return;
        
        //up stop
        if ((dy < 0) && (y < 10)) 
            return;
        
        //down stop
        if ((dy > 0) && (y > 710 - image.getHeight(null))) 
            return;
        
        //check for image change
        if(dy < 0)
            this.image = new ImageIcon(this.getClass().getResource("../sprites/ship_u_tilt.png")).getImage();
        else if (dy > 0)
            this.image = new ImageIcon(this.getClass().getResource("../sprites/ship_d_tilt.png")).getImage();
        else
            this.image = new ImageIcon(this.getClass().getResource("../sprites/ship.png")).getImage();
        

        x += (delta * dx) / 1000;
        y += (delta * dy) / 1000;
    }
    
    public void setHorizontalMovement(double dx) 
    {
        this.dx = dx;
    }

    public void setVerticalMovement(double dy) 
    {
        this.dy = dy;
    }

    public double getHorizontalMovement() 
    {
        return dx;
    }

    public double getVerticalMovement() 
    {
        return dy;
    }
        
    public void draw(Graphics g)
    {
        g.drawImage(image, x, y, null);
        
        //anims
        //List<Image> sprites = new ArrayList<Image>();
        //sprites.add(new ImageIcon(this.getClass().getResource("../sprites/thrust1.PNG")).getImage());
        //sprites.add(new ImageIcon(this.getClass().getResource("../sprites/thrust2.PNG")).getImage());
        
        //Animation shipThrust = new Animation(g, sprites, x-13, y+34, 1000);
        //shipThrust.play();
    }
    
    public int getX()
    {
        return x;
    }
    
    public int getY()
    {
        return y;
    }
}
